<?php

namespace App\Winged;
use App\Winged\Auth\Backend\Api\Api;
use Closure;
use App\Winged\Components\Content;
use Illuminate\Http\Request;

class WingedController extends \App\Http\Controllers\Controller
{
	function __construct()
    {
    }
    /**
    * @param Closure $callable
    *
    * @return \App\Winged\Components\Content
    */
    public function Content(Closure $callable = null)
    {
        return new Content($callable);
    }


    public function transfer(Request $request)
    {
        $path   = $request->input('path');
        $params = $request->input('params' , null);
        $method = strtoupper($request->input('method' , 'GET'));
        try {
            list($status , $content) = Api::doTransfer($path ,$method , $params);
            return response()
                ->json(['status' => $status, 'content' => $content]);
        }
        catch (\Exception $e) {
            return response()->json(['msg' => $e->getMessage() , 'status' => 500]);
        }
    }

}
